package cn.dulian.spring5.testdemo;

import cn.dulian.spring5.config.SpringConfig;
import cn.dulian.spring5.service.UserService;
import org.junit.Test;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.net.UnknownServiceException;

/**
 * @author dulian
 * @create 2022-04-15 13:40
 */
public class TestSpringDemo {
    @Test
    public void testService1(){
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("bean.xml");
        UserService userService = context.getBean("userService", UserService.class);
        userService.add();
    }

    @Test
    public void testService2(){
        AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(SpringConfig.class);
        UserService userService = annotationConfigApplicationContext.getBean("userService", UserService.class);
        userService.add();
    }
}
